package su.myspringapps.online_school_learning_spring_data_jpa.repository;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import su.myspringapps.online_school_learning_spring_data_jpa.entity.Teacher;
import su.myspringapps.online_school_learning_spring_data_jpa.repository.main_db.TeacherRepository;

import java.util.List;

@SpringBootTest
class TeacherRepositoryTest {

    @Autowired
    TeacherRepository teacherRepository;

    @Test
    void geMeAllTeachers() {
        List<Teacher> teacherList = teacherRepository.geMeAllTeachers();
        Teacher actualTeacher1 = teacherList.get(0);
        Teacher actualTeacher2 = teacherList.get(1);
        Assertions.assertEquals(1, actualTeacher1.getId());
        Assertions.assertEquals("Ягешев Сидор", actualTeacher1.getName());
        Assertions.assertEquals(10000, actualTeacher1.getSalary());
        Assertions.assertEquals(18, actualTeacher1.getAge());
        Assertions.assertEquals(2, actualTeacher2.getId());
        Assertions.assertEquals("Яглинцев Владислав", actualTeacher2.getName());
        Assertions.assertEquals(20000, actualTeacher2.getSalary());
        Assertions.assertEquals(19, actualTeacher2.getAge());
    }

    @Test
    void giveMeTeacherById() {
        Teacher actualTeacher = teacherRepository.giveMeTeacherById(1);
        Assertions.assertEquals("Ягешев Сидор", actualTeacher.getName());
        Assertions.assertEquals(10000, actualTeacher.getSalary());
        Assertions.assertEquals(18, actualTeacher.getAge());
    }

    @Test
    void giveMeTeacherByNameAndAge() {
        Teacher actualTeacher = teacherRepository.giveMeTeacherByNameAndAge("Ягешев Сидор", 18);
        Assertions.assertEquals("Ягешев Сидор", actualTeacher.getName());
        Assertions.assertEquals(10000, actualTeacher.getSalary());
        Assertions.assertEquals(18, actualTeacher.getAge());
    }

    @Test
    void giveMeTeacherByNameAndAgeUsingParam() {
        Teacher actualTeacher = teacherRepository.giveMeTeacherByNameAndAgeUsingParam("Ягешев Сидор", 18);
        Assertions.assertEquals("Ягешев Сидор", actualTeacher.getName());
        Assertions.assertEquals(10000, actualTeacher.getSalary());
        Assertions.assertEquals(18, actualTeacher.getAge());
    }
}